package com.sheepone.util.string;

import java.io.Serializable;

/**
 * @author Miss.杨
 * @description
 * @since 2024/3/9 - 21:30
 */
public class SerializableUtil {
    public static <T> T getValue(Serializable serializable,Class<T> clazz) {
        if (serializable == null || clazz == null) {
            throw new IllegalArgumentException("Arguments cannot be null");
        }
        if (clazz.isInstance(serializable)) {
            return clazz.cast(serializable);
        }
        throw new IllegalArgumentException("Arguments cannot be casted");
    }

    public static void main(String[] args) {
        String str = "123";
        System.out.println(getValue(str, String.class));

        Integer integer = 123;
        System.out.println(getValue(integer, Integer.class));

        Long long1 = 123L;
        System.out.println(getValue(long1, Long.class));
    }
}
